package pl.koszolko.documentclustering.cluster.document;

import pl.koszolko.documentclustering.dao.Document;

public class DocumentClusteringByReferencesAndCitedBy extends
		DocumentForClustering {

	private static final long serialVersionUID = 1L;

	public DocumentClusteringByReferencesAndCitedBy(Document doc) {
		super(doc);
	}
	
	@Override
	/**
	 * Oblicza podobienstwo na podstawie listy artykulow cytujacych oraz artykulow cytowanych
	 */
	public double countSimilarity(DocumentForClustering document) {
		double allReferences =  getCitedBySize() + getReferencesSize();
		double commonReferences = 0;
		
		for(Document docRef : document.getCitedBy()) {
			if(ifCitedByContains(docRef)) {
				++commonReferences;
			} else {
				++allReferences;
			}
		}
		
		for(Document docRef : document.getReferences()) {
			if(ifReferencesContains(docRef)) {
				++commonReferences;
			} else {
				++allReferences;
			}
		}
		
		if(allReferences == 0)
			return 0D;
		else
			return commonReferences/allReferences;
	}
}
